//
//  LGProductDetail_Controller.m
//  LoveTravel
//
//  Created by MS on 16-1-22.
//  Copyright (c) 2016年 Lemon. All rights reserved.
//

#import "LGProductDetail_Controller.h"
#import "ProductDetailDataTool.h"
#import "ProductDetailView.h"
#import "Product_Detail_Frame.h"
@interface LGProductDetail_Controller ()

@property (nonatomic,assign) BOOL hidden;
@property (nonatomic,weak) MyNavigationBar * navBar;
@property (nonatomic,weak) MyNavigationItem * leftItem;
@property (nonatomic,weak) ProductDetailView * productView;
@property (nonatomic,strong) Product_Detail_Frame * product_Frame;
@end

@implementation LGProductDetail_Controller

-(ProductDetailView *)productView
{
    if (!_productView) {
        ProductDetailView * view = [[ProductDetailView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:view];
        _productView = view;
    }
    return _productView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.product_Frame = [[Product_Detail_Frame alloc] init];
    
    
//    NSLog(@"id_recomm- %ld",self.recomm_Data.id_recomm);
    
    [self setUpnavigation];
    [self loadProductDetailData];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeNav:) name:@"SetNav" object:nil];
}

-(void)setUpnavigation
{
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"navi_bg"] andHighImage:[UIImage imageNamed:@"navi_bg"] target:nil action:nil forControlEvents:UIControlEventTouchUpInside];
    
    MyNavigationItem * left = [MyNavigationItem navigationItemWithImage:@"btn_back1" andHighlightImage:@"btn_back2" andTag:0 andTitle:nil addTarget:self action:@selector(btnClick:)];
    
    MyNavigationItem * right1 = [MyNavigationItem navigationItemWithImage:@"activity_btnShare" andHighlightImage:@"btn_share_red" andTag:1 andTitle:nil addTarget:self action:@selector(btnClick:)];
    
//    MyNavigationItem * right2 = [MyNavigationItem navigationItemWithImage:@"activity_btnUnLike" andHighlightImage:@"like_red" andTag:2 andTitle:nil addTarget:self action:@selector(btnClick:)];// @"activity_btnUnLike_red"
    
    MyNavigationBar * navBar = [[MyNavigationBar alloc] init];
    
    [navBar setNavigationBarWithBgImageName:@"navi_bg" andTitle:nil andTitleView:nil andLeftItems:@[left] andRightItems:@[right1]];
    
    self.navBar = navBar;

    [[UIApplication sharedApplication].keyWindow addSubview:navBar];
    
}

-(void)btnClick:(UIButton *)btn
{
    if (btn.tag==0) {
         [self.navigationController popViewControllerAnimated:YES];
    }
    
}





-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
     [self.navigationController setNavigationBarHidden:YES];
}



-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [self.navBar removeFromSuperview];
}

-(void)changeNav:(NSNotification *)note
{
    BOOL flag =[note.userInfo[@"NavChange"] boolValue];
    
    [self.navigationController setNavigationBarHidden:flag];

    ((UIButton *)self.navBar.leftItems[0]).selected = !flag;
    
    for (UIButton * btn in self.navBar.rightItems) {
        btn.selected = !flag;
    }

    
}


-(void)loadProductDetailData
{
    /**
     *     详情数据
     */
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [ProductDetailDataTool getProductDetailDataWithId:self.recomm_Data.id_recomm Succuss:^(ProductDetailModel *data) {
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        self.product_Frame.productData = data;
        
        self.productView.product_Frame = self.product_Frame;
        
    } failure:^(NSError *error) {
        
    }];
    
    
    /**
     *     评论数据
     */
    [ProductDetailDataTool getProductDetail_CommentDataWithId:self.recomm_Data.id_recomm Succuss:^(Product_CommentModel *data) {
       
       
        
    } failure:^(NSError *error) {
        
    }];
    
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
